import Loding from "@/assets/Loding.svg"
import style from "./loading.module.less"
function getLoadingImage(el){
  // 查找有无img标签
  return el.querySelector("img[data-role=loding]");
}

function createLoadingImag(){
  // 创建img标签
  const img = document.createElement("img");
  img.dataset.role = "loding";
  img.src = Loding;
  img.className = style.loading;
  return img;
}
export default function (el,binding){
  const curImg = getLoadingImage(el);
  // 根据binding.vulue的值 决定创建或删除img元素
  if(binding.value){
    // 如果没有img元素 则创建
    if(!curImg){
      const img = createLoadingImag();
      el.appendChild(img);
    }
  }else{
    if(curImg){
      curImg.remove();
    }
  }
}